﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FindAllArea.aspx.cs" Inherits="HZ.Supervise.Web.Common.FindAllArea" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>选择地区</title>
    <link rel="stylesheet" type="text/css" href="../style/global.css" />

    <script type="text/javascript" src="../scripts/jquery.js"></script>

    <script type="text/javascript" src="../scripts/mainlistSelect.js"></script>

    <script type="text/javascript" src="../scripts/Common.js"></script>

    <script type="text/javascript" src="../scripts/global.js"></script>

    <script type="text/javascript" language="javascript">
        function addAreaInfo() {
            var AreaInfo;
            AreaInfo = document.getElementById("AreaName").value + "|" + document.getElementById("AreaId").value;
            window.parent.insertAreaInfo(AreaInfo);
            window.parent.hidePopWin(false);
        }

        function chkAllCompany() {
            CheckBoxList = document.getElementsByName("chkArea");
            for (var i = 0; i < CheckBoxList.length; i++) {
                CheckBoxList[i].checked = true;
            }
        }


        function insertCompanyInfo() {

            if (!checkSelectedItems('gvwAreaList', '请至少选择一项！')) {
                return false;
            }

            CheckBoxList = document.getElementsByName("chkArea");
            var resultValue = "";
            var hosNames = "";
            var hosIDs = "";
            for (var i = 0; i < CheckBoxList.length; i++) {
                if (CheckBoxList[i].checked) {
                    resultValue = CheckBoxList[i].value;
                    tempId = resultValue.split("|")[0];
                    tempName = resultValue.split("|")[1];

                    hosIDs = hosIDs + tempId + ",";
                    hosNames = hosNames + tempName + ",";
                }
            }

            var listbox = document.getElementById("ListArea");
            var hosID = document.getElementById("AreaId");
            var hosName = document.getElementById("AreaName");
            var arrayName = hosNames.split(',');
            var arrayID = hosIDs.split(',');
            var isUnique = true;
            var temp;
            for (m = 0; m < arrayID.length; m++) {
                for (n = 0; n < listbox.options.length; n++) {
                    if (arrayID[m] == listbox.options[n].value) {
                        isUnique = false;
                        temp = arrayName[m];
                        break;
                    }
                }
            }

            if (isUnique == true) {
                for (var i = 0; i < arrayName.length; i++) {
                    if (!isNull(arrayName[i])) {
                        var listItem = document.createElement("OPTION");
                        listItem.text = arrayName[i];
                        listItem.value = arrayID[i];
                        listbox.add(listItem);
                    }
                }
            }
            else {
                alert("地区" + temp + "已经存在！");
                return;
            }
            hosID.value = "";
            hosName.value = "";
            for (j = listbox.options.length - 1; j >= 0; j--) {
                hosID.value += listbox[j].value + ",";
                hosName.value += listbox[j].text + ",";
            }
        }

        function deleteCompany() {
            if (!isNull(checkSelected())) {
                var info = checkSelected();
                alert(info);
                return;
            }
            var listbox = document.getElementById("ListArea");
            var companyID = document.getElementById("AreaId");
            var companyName = document.getElementById("AreaName");
            companyID.value = "";
            companyName.value = "";

            var selectindex = listbox.selectedIndex;
            listbox.remove(selectindex);

            for (j = listbox.options.length - 1; j >= 0; j--) {
                companyID.value = companyID.value + listbox[j].value + ",";
                companyName.value = companyName.value + listbox[j].text + ",";
            }
        }

        function checkSelected() {
            var info;
            var listbox = document.getElementById("ListArea");
            var selectindex = listbox.selectedIndex;
            if (selectindex < 0) {
                info = "请选择要删除的地区！";
                return info;
            }
            return "";
        }

        function isNull(str) {
            var re = /^[ \s]*$/;
            return re.test(str);
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <table class="querylist">
        <tr>
            <td width="40%">
                选择地区：
            </td>
            <td width="20%">
                &nbsp;
            </td>
            <td width="40%">
                对比地区：
            </td>
        </tr>
        <tr>
            <td>
                <asp:GridView ID="gvwAreaList" runat="server" CssClass="mainlist" AutoGenerateColumns="False"
                    DataKeyNames="AreaID" OnRowDataBound="gvwselect_RowDataBound" EmptyDataText="暂无符合条件的数据！">
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <input id="chkAllArea" name="chkAllArea" type="checkbox" onclick="SelectAllCheckboxes(this,'gvwAreaList','chkAllArea');" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <input id="chkArea" name="chkArea" type="checkbox" onclick="chkChecked(this,'gvwAreaList','chkAllArea');"
                                    value='<%# Eval("AreaID") %>|<%# Eval("AreaName") %>'> </input>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="地区名称">
                            <ItemTemplate>
                                <asp:Label ID="lblAreaName" runat="server" Text='<%# Eval("AreaName") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Left" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <webdiyer:AspNetPager ID="AspNetPager1" runat="server" CustomInfoHTML="" CustomInfoStyle="display:none"
                    NumericButtonCount="5" OnPageChanged="AspNetPager1_PageChanged" ReverseUrlPageIndex="false"
                    ShowDisabledButtons="False" ShowFirstLast="False" ShowMoreButtons="false" ShowPageSizeBox="false"
                    ShowPrevNext="False">
                </webdiyer:AspNetPager>
            </td>
            <td>
                <p>
                    <input type="button" id="btnIn" value="加入对比" class="btn" onclick="insertCompanyInfo();" /></p>
                <p>
                    <input type="button" id="btnOut" value="删除对比" class="btn" onclick="deleteCompany();" /></p>
                <p>
                    <input type="button" id="btnOk" value="确认对比" class="btn" onclick="return addAreaInfo();" /></p>
            </td>
            <td rowspan="2">
                <input id="AreaId" type="hidden" name="HosId" runat="server" />
                <asp:ListBox ID="ListArea" runat="server" Height="300px" Width="100%"></asp:ListBox>
                <input id="AreaName" type="hidden" name="HosName" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
